<html lang="zh">
    <meta content="text/html; charset=utf-8" http-equiv="content-type" />
    <style>
        iframe {
            border: 0px;
            margin: 20px auto;
        }
        .btn {
            width: 60%;
            height: 60;
            border: 1px solid #FFFFFF;
            background: #3F85ED;
            border-radius: 10px 10px 10px 10px;
            text-align: center;
            margin: 50px auto;
        }
        .btn .btn-lebal {
            /* position: absolute; */
            display: inline-block;
            font-family: '雅黑';
            font-size: 30pt;
            padding: 5px auto;
            left: 50%;
            top: 50%;
        }
        #tips {
            font-family: '雅黑';
            font-size: 24pt;
        }
    </style>
    <body>
        <div class="btn" onclick="window.open('https://uua.jr.jd.com/uc-fe-wxgrowing/cloudpig/index/home/20191030/158432123100870350/')">
            <span class="btn-lebal">京东养猪</span>
        </div>
        <div class="btn" onclick="openJddWindow()">
            <a id="open-link" style="display: none" target="_blank"></a>
            <span class="btn-lebal">自动收集其他京东豆</span>
        </div>
        <div>
            <label id="tips" style="text-align: center;">1、登录京东账号； 2、点击领取任务按钮； 3、点击开始收集按钮</label>
        </div>
        <div id="jd-page"></div>
    </body>
    <script type="application/javascript">
        // 
        function openJddWindow (){
            const urls = [
                `https://jddx.jd.com/m/jddnew/center/mall/index.html?utm_source=Android%2aurl%2a${new Date().getTime()}&utm_medium=jrappshare&utm_term=wxfriends&from=jrdaka&final_page=xxf_jx`,
                `https://jddx.jd.com/m/jddnew/btyingxiao/sfstore/index.html?utm_source=Android%2aurl%2a${new Date().getTime()}&utm_medium=jrappshare&utm_term=wxfriends&from=jrdaka&final_page=xxf_jx`,
                `https://jddx.jd.com/m/jddnew/activity/vault/index.html?utm_source=Android%2aurl%2a${new Date().getTime()}&utm_medium=jrappshare&utm_term=wxfriends&from=jrdaka&final_page=xxf_gjf`,
                `https://jddx.jd.com/m/jddnew/zc.html?utm_source=Android%2aurl%2a${new Date().getTime()}&utm_medium=jrappshare&utm_term=wxfriends`,
                `https://vip.m.jd.com/newPage/reward/reward` // 摇一摇
            ]
            var a = document.getElementById("open-link");
            urls.forEach((url, index) => {
                console.log(`打开 ${url}`)
                window.open(url);
            })
        }


        // 1、从京东商场领取任务
        // 2、自动刷新对应任务业务
        const pages = [
            {name: '精选', url: 'https://jddx.jd.com/m/jddnew/center/mall/index.html'},
            {name: '分期免息', url: 'https://jddx.jd.com/m/jddnew/btyingxiao/sfstore/index.html'},
            {name: '众筹', url: 'https://jddx.jd.com/m/jddnew/zc.html'},
            {name: '9块9', url: 'https://jddx.jd.com/m/jddnew/mall9_9/index.html'},
            {name: '购就返', url: 'https://jddx.jd.com/m/jddnew/activity/vault/index.html'},
            {name: '逛故宫', url: 'https://jddx.jd.com/m/museum/index.html?from=zqtogugong'}
        ]
        const mainPageUri = 'https://jddx.jd.com/m/jddnew/money/index.html'
        /// 摇京东豆： https://vip.m.jd.com/newPage/reward/g
        

        var clientWidth = document.body.offsetWidth;
        const taskCount = 3; // 任务次数

        // 显示主页
        function showMainPage () {
            document.getElementById('jd-page').innerHTML = `
            <div>
                <div class="btn"  onclick="showRefreashTaskPage()">
                    <span class="btn-lebal">开始收集</span>
                </div>
                <iframe id="mainFrame" src="${mainPageUri}" name="赚钱" height="1080" width="${clientWidth}"></iframe>
            </div>`
        }
        showMainPage()

        // 显示刷新任务页
        function showRefreashTaskPage () {
            document.getElementById('jd-page').innerHTML = ''
            // 根据 pages 参数，生成对应的
            var detailPage = document.getElementById('jd-page')
            pages.forEach((page, index) => {
                var frame = document.createElement('iframe')
                frame.width = clientWidth / 2 - 20
                frame.height = 400
                if (index % 2 == 0) {
                    frame.style.margin = '30 20 30 0';
                } else {
                    frame.style.margin = '30 0 30 20';
                }
                frame.src = page.url
                frame.onload = frameLoadedHandler
                detailPage.appendChild(frame)
            })
        }

        var refreashCount = 0   // 总任务刷新次数
        var frameLoadedCount = 0    // 当前页，frame刷新个数
        function frameLoadedHandler () {
            if (++frameLoadedCount < pages.length) {
                return
            }
            if (++refreashCount < taskCount) {
                document.getElementById('tips').innerText = `第 ${refreashCount} 次刷新`
                setTimeout(() => {
                    frameLoadedCount = 0
                    showRefreashTaskPage()
                }, 60*1000+3000)
            } else {
                document.getElementById('tips').innerText = `已完成 ${taskCount} 次刷新，可以捡起你的京东豆了`
                frameLoadedCount = 0
                refreashCount = 0
                showMainPage()
            }
        }
    </script>
</html>